﻿using IS_Ever_Green.DataAccess.Model;
using IS_Ever_Green.DataAccess.Model.Repositories;


namespace IS_Ever_Green.Tests
{
    [TestFixture]
    public class UserRepositoryTests
    {
        private IUserRepository _userRepository;

        [SetUp]
        public void Setup()
        {
            _userRepository = new UserRepository();
        }

        [Test]
        public void UserExists_ExistingUser_ReturnsTrue()
        {
            // Arrange
            string existingUserLogin = "User";

            // Act
            bool userExists = _userRepository.UserExists(existingUserLogin);

            // Assert
            Assert.IsTrue(userExists);
        }

        [Test]
        public void UserExists_NonExistingUser_ReturnsFalse()
        {
            // Arrange
            string nonExistingUserLogin = "123";

            // Act
            bool userExists = _userRepository.UserExists(nonExistingUserLogin);

            // Assert
            Assert.IsFalse(userExists);
        }

        [Test]
        public void RegisterUser_NewUser_UserRegistered()
        {
            // Arrange
            var user = new UserModel
            {
                LoginUser = "testuser",
                Password = "testpassword",
                RoleId = 1
              
            };

            // Act
            _userRepository.RegisterUser(user);

            // Assert
            Assert.IsTrue(_userRepository.UserExists("testuser"));
        }

        [Test]
        public void AuthenticateUser_ExistingUser_CorrectAuthentication()
        {
            // Arrange
            var user = new UserModel
            {
                LoginUser = "existinguser",
                Password = "correctpassword",
                RoleId = 1
            };
            _userRepository.RegisterUser(user);

            // Act
            var authenticatedUser = _userRepository.AuthenticateUser("existinguser", "correctpassword");

            // Assert
            Assert.IsNotNull(authenticatedUser);
            Assert.AreEqual("existinguser", authenticatedUser.LoginUser);
        }
    }
}
